/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wudtcalc;

import au.com.bytecode.opencsv.CSVReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.Scanner;

/**
 *
 * @author jzajaczek
 */
public class DataContainer {
    File log = new File("log.txt"); 
    public DecimalFormat df2 = new DecimalFormat("#.##");
    private int val;
    private String medium;
    private String po_;
    private String to_;
    private String gasket_name;
    private String dz_;
    private String dw_;
    private String g_;

    private double po;
    private double to;
    private double sigma_m;
    private double sigma_r;
    private double b[] = new double[6];
    private double b_20;
    private double b_100;
    private double b_200;
    private double b_300;
    private double b_400;
    private double b_500;
    private double dz;
    private double dw;
    private double g;
    
   DataContainer() {};

    
    public void ReadCSVFile() throws IOException {
        //http://viralpatel.net/blogs/java-read-write-csv-file/
        int i = 0;
        String csvFilename = "test.csv";
        
        try (CSVReader csvReader = new CSVReader(new FileReader(csvFilename), ';')) {
            String[] pos = null;
            while((pos = csvReader.readNext()) != null) {
                System.out.println("Linia " + i);
                if (i == 0) {
                    medium = pos[0];
                    po_ = pos[1];
                    to_ = pos[2];
                    gasket_name = pos[3];
                    dz_ = pos[4];
                    dw_ = pos[5];
                    g_ = pos[6];
                } else {
                    medium = pos[0];
                    po = Double.valueOf(pos[1]);
                    to = Double.valueOf(pos[2]);
                    gasket_name = pos[3];
                    dz = Double.valueOf(pos[4]);
                    dw = Double.valueOf(pos[5]);
                    g = Double.valueOf(pos[6]);
                    sigma_m = Double.valueOf(pos[7]);
                    sigma_r = Double.valueOf(pos[8]);
                    b[0] = Double.valueOf(pos[9]);
                    b[1] = Double.valueOf(pos[10]);
                    b[2] = Double.valueOf(pos[11]);
                    b[3] = Double.valueOf(pos[12]);
                    b[4] = Double.valueOf(pos[13]);
                    b[5] = Double.valueOf(pos[14]);
                }    
                    if (i == 0) {
                        System.out.println(medium + ";" + po_ + ";" + to_);  
                        System.out.println(gasket_name + ";" + dz_ + "/" + dw_ + "/" + g_);
                    }
                    else {   
                        System.out.println(medium + " ; " + po + " ; " + to);
                        System.out.println(gasket_name);
                        System.out.println(dz);
                        System.out.println(dw);
                        System.out.println(g);
                        System.out.println(sigma_m);
                        System.out.println(sigma_r);
                    }
                    if (i != 0) {
                        CalcRoad cr = new CalcRoad(this);
                        cr.Road();
              
                        System.out.println("Wyniki uszczelki nr " + i);
                        System.out.println("Geometria uszczelki:");
                        System.out.println("U = " + df2.format(cr.U_) + " ; Ucz = " + df2.format(cr.Ucz_) + " ; " + cr.sDu_ + df2.format(cr.Du_) + "[mm]");
                        System.out.println("Siły i momenty na uszczelce:");
                        System.out.println("SigR = " + df2.format(cr.SigR_) + "; P = " + df2.format(cr.P_) + "[N]" + "; S = " + df2.format(cr.S_) + "[N]");
                        System.out.println("Nr = " + df2.format(cr.Nr_) + "[N]");
                        System.out.println("Nm1 = " + df2.format(cr.Nm1_) + "[N]");
                        System.out.println("Nm2 = " + df2.format(cr.Nm2_) + "[N]");
                        System.out.println("N = " + df2.format(cr.N_) + "[N]");
                    }
                i = i + 1;
                
            }
        } catch(NumberFormatException e) {
            System.out.println("To nie jest liczba");
        }          
    }
    
    public void ReadTextFile() throws FileNotFoundException, IOException {
        FileReader file = null;
        String line;
        String st = "";
        float valt = 0;
        char sign;
        
      
        try {
            file = new FileReader("data.txt");
            BufferedReader br = new BufferedReader(file);
            
            line = br.readLine();

            for (int i=0; i<line.length(); i++) {
                sign = line.charAt(i);
                if (sign != ','){
                    st = st + Character.toString(sign); 

                } else {
                    //float fl = Float.parseFloat(Character.toString(sign));
                    Float fl = new Float(st);
                    //valt = valt + fl;
                    System.out.println(fl);
                    
                    fl = null;
                }    
               
            }

        } catch(FileNotFoundException e) {
            System.out.print("Brak pliku o podanej nazwie.");
        } catch(IOException e) {
            System.out.print("Problem z odczytem pliku.");
        } finally {
            if (file != null) {
                file.close();
            }
        }
    }
    
    
    public void Load() throws FileNotFoundException, IOException {
        FileReader fileReader = new FileReader("data.txt");
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line = bufferedReader.readLine();
        int lineLength = line.length();
        int licznik = 0;
        while(licznik <= lineLength) {

        }
        
        do {
            System.out.println(line);
            line = bufferedReader.readLine();
        } while (line != null);
        bufferedReader.close();
        
        
        try (Scanner inputLog = new Scanner(System.in)) {
            System.out.println("Wprowadź wartośc danej val");
            val = inputLog.nextInt();
        }
    }

    public void Save() throws FileNotFoundException {
        try (PrintWriter outputLog = new PrintWriter(log)) {
            outputLog.flush();
            Date date = new Date();
            outputLog.println(date);
            outputLog.println("val1 = " + val);
            System.out.println("val1 = " + val);
            outputLog.close();
        }
    }

    /**
     * @return the dz
     */
    public double getDz() {
        return dz;
    }

    /**
     * @param dz the dz to_ set
     */
    public void setDz(double dz) {
        this.dz = dz;
    }

    /**
     * @return the dw
     */
    public double getDw() {
        return dw;
    }

    /**
     * @param dw the dw to_ set
     */
    public void setDw(double dw) {
        this.dw = dw;
    }

    /**
     * @return the gasket_name
     */
    public String getGasket_name() {
        return gasket_name;
    }

    /**
     * @return the dz_
     */
    public String getDz_() {
        return dz_;
    }

    /**
     * @return the dw_
     */
    public String getDw_() {
        return dw_;
    }

    /**
     * @return the sigma_m
     */
    public double getSigma_m() {
        return sigma_m;
    }

    /**
     * @return the sigma_r
     */
    public double getSigma_r() {
        return sigma_r;
    }

    /**
     * @return the b_20
     */
    public double getB_20() {
        return b_20;
    }

    /**
     * @return the b_100
     */
    public double getB_100() {
        return b_100;
    }

    /**
     * @return the b_200
     */
    public double getB_200() {
        return b_200;
    }

    /**
     * @return the b_300
     */
    public double getB_300() {
        return b_300;
    }

    /**
     * @return the b_400
     */
    public double getB_400() {
        return b_400;
    }

    /**
     * @return the b_500
     */
    public double getB_500() {
        return b_500;
    }

    /**
     * @param dz_ the dz_ to_ set
     */
    public void setDz_(String dz_) {
        this.dz_ = dz_;
    }

    /**
     * @param dw_ the dw_ to_ set
     */
    public void setDw_(String dw_) {
        this.dw_ = dw_;
    }

    /**
     * @return the g
     */
    public double getG() {
        return g;
    }

    /**
     * @param g the g to_ set
     */
    public void setG(double g) {
        this.g = g;
    }

    /**
     * @param sigma_m the sigma_m to_ set
     */
    public void setSigma_m(double Sigma_m) {
        this.sigma_m = Sigma_m;
    }

    /**
     * @param sigma_r the sigma_r to_ set
     */
    public void setSigma_r(double Sigma_r) {
        this.sigma_r = Sigma_r;
    }

    /**
     * @param b_20 the b_20 to_ set
     */
    public void setB_20(double b_20) {
        this.b_20 = b_20;
    }

    /**
     * @param b_100 the b_100 to_ set
     */
    public void setB_100(double b_100) {
        this.b_100 = b_100;
    }

    /**
     * @param b_200 the b_200 to_ set
     */
    public void setB_200(double b_200) {
        this.b_200 = b_200;
    }

    /**
     * @param b_300 the b_300 to_ set
     */
    public void setB_300(double b_300) {
        this.b_300 = b_300;
    }

    /**
     * @param b_400 the b_400 to_ set
     */
    public void setB_400(double b_400) {
        this.b_400 = b_400;
    }

    /**
     * @param b_500 the b_500 to_ set
     */
    public void setB_500(double b_500) {
        this.b_500 = b_500;
    }

    /**
     * @return the medium
     */
    public String getMedium() {
        return medium;
    }

    /**
     * @param medium the medium to_ set
     */
    public void setMedium(String medium) {
        this.medium = medium;
    }

    /**
     * @return the po_
     */
    public String getPo_() {
        return po_;
    }

    /**
     * @param po_ the po_ to_ set
     */
    public void setPo_(String po_) {
        this.po_ = po_;
    }

    /**
     * @return the to_
     */
    public String getTo_() {
        return to_;
    }

    /**
     * @param to_ the to_ to_ set
     */
    public void setTo_(String to_) {
        this.to_ = to_;
    }

    /**
     * @return the po
     */
    public double getPo() {
        return po;
    }

    /**
     * @param po the po to set
     */
    public void setPo(double po) {
        this.po = po;
    }

    /**
     * @return the to
     */
    public double getTo() {
        return to;
    }

    /**
     * @param to the to to set
     */
    public void setTo(double to) {
        this.to = to;
    }

    /**
     * @return the g_
     */
    public String getG_() {
        return g_;
    }

    /**
     * @param g_ the g_ to set
     */
    public void setG_(String g_) {
        this.g_ = g_;
    }

    /**
     * @return the b
     */
    public double[] getB() {
        return b;
    }

    /**
     * @param b the b to set
     */
    public void setB(double[] b) {
        this.b = b;
    }
  
}
